﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _5_30_OC_OD
{
    public partial class Form1 : Form
    {

        double m;
        double n;
        double e1_x;
        double e1_y;
        double e2_x;
        double e2_y;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnPicture_Click(object sender, EventArgs e)
        {
            // 示意图
            Form2 f = new Form2();
            f.ShowDialog();


        }

        private void btnCount_Click(object sender, EventArgs e)
        {
            try
            {
                m = Convert.ToDouble(txtm.Text.Trim());
                n = Convert.ToDouble(txtn.Text.Trim());
                e1_x = Convert.ToDouble(txte1x.Text.Trim());
                e1_y = Convert.ToDouble(txte1y.Text.Trim());
                e2_x = Convert.ToDouble(txte2x.Text.Trim());
                e2_y = Convert.ToDouble(txte2y.Text.Trim());

            }
            catch
            {
                MessageBox.Show("m或n或e1或e2不能为空");
                return;

            }
            determine d = new determine();
            d.GetDetermine(m, n);
            if (m == 0 || n == 0)
            {
                txtocx.Clear();
                txtocy.Clear();
                txtodx.Clear();
                txtodx.Clear();
            }
            else
            {
                
                double[] e1_vector = new double[2] { e1_x, e1_y };
                double[] e2_vector = new double[2] { e2_x, e2_y };

                double[] OC_vctor = new double[2] { 0, 0 };
                OC_vctor[0] = (m - 1) / m * e1_vector[0] + (1 / m) * e2_vector[0];
                OC_vctor[1] = (m - 1) / m * e1_vector[1] + (1 / m) * e2_vector[1];

                double[] OD_vector = new double[2] { 0, 0 };
                OD_vector[0] = (n - 1) / n * e2_vector[0] + (1 / n) * e1_vector[0];
                OD_vector[1] = (n - 1) / n * e2_vector[1] + (1 / n) * e1_vector[1];

                txtocx.Text = OC_vctor[0].ToString();
                txtocy.Text = OC_vctor[1].ToString();
                txtodx.Text = OD_vector[0].ToString();
                txtody.Text = OD_vector[1].ToString();



            }
        }

        private void txtm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != '\b')
            {
                if (e.KeyChar < '0' || e.KeyChar > '9')
                {
                    e.Handled = true;
                }
            }
        }




    }
}
